package com.wunong.smart.bigdata.jdk;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.IntStream;

/**
 * @author created by zealot.zt
 */
public class ForkJoinClient {

    public static void main(String[] args) throws Exception {
        ForkJoinPool pool = new ForkJoinPool();

        for (int i = 0; i < 100; i++) {
            // 创建数组
            final int from = 1;
            final int end = 11;
            int[] values = IntStream.range(from, end).toArray();

            // 执行任务
            ForkJoinTask<Integer> task = pool.submit(new SumArrayForkJoinTask(values));

            // 输出信息
            System.out.println("[" + from + "," + end + "] sum:" + task.get() + "\n");
        }
    }
}